<template>
  <div>
    <el-card class="oneCard" @click.native="jump">
      <div>
        <div>
          <el-link :type="type" :underline="false">{{ total }}</el-link>
          <h2>{{ name }}</h2>
        </div>
        <div><svg-icon :icon-class="icon" /></div>
      </div>
    </el-card>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { finishedTotalTasks } from '@neu/dcom-ui/api/hnInspectionTask'
export default {
  name: 'DailyInspection',
  data() {
    return {
      icon: 'plan',
      type: 'warning',
      total: 0,
      name: '已完日巡检（次）'
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  mounted() {
    this.getTotal()
  },
  methods: {
    // 获取数量
    getTotal() {
      finishedTotalTasks().then(res => {
        this.total = res.data ? res.data : 0
      })
    },
    isWorker() {
      return this.roles.some(r => r === 'worker')
    },
    jump() {
      if (this.isWorker()) {
        this.$router.push({ name: 'hn_hnInspectionTask', params: { s_status: 'finished' }})
      } else {
        this.$router.push({ name: 'hn_dailyInspectionStats', params: { status: 'finished' }})
      }
    }
  }
}
</script>
